package org.example.controller;

import org.example.exception.BusinessException;
import org.example.exception.SystemException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
//@ControllerAdvice
//@ResponseBody
public class ProjectExceptionAdvice {
    @ExceptionHandler(SystemException.class)
    public Result doSystemException(SystemException e)
    {
        System.out.println("出现异常");

        return new Result( null, e.getCode(), e.getMessage());
    }
    @ExceptionHandler(BusinessException.class)
    public Result doBusinessException(BusinessException e)
    {
        System.out.println("出现异常");

        return new Result(null,  e.getCode(), "系统繁忙请稍后再试，运行异常");
    }
    @ExceptionHandler(Exception.class)
    public Result doException(Exception e)
    {
        System.out.println("出现异常");

        return new Result(null, Code.SYSTEM_UNKNOW_ERR, "系统繁忙请稍后再试，未知异常");
    }
}
